import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import 'element-plus/dist/index.css'
import Echarts from 'vue-echarts'
import * as echarts from 'echarts'

import App from './App.vue'
import router from './router'
import vueI18n from './i18n'

// axios.defaults.baseURL = '/api'
const app = createApp(App)
import * as buffer from 'buffer'
import axios from 'axios' //引入buffer

if (typeof (window as any).Buffer === 'undefined') {
  // 判断当前环境是否有Buffer对象
  ;(window as any).Buffer = buffer.Buffer // Buffer对象不存在则创建导入的buffer
}

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 注册echarts图表组件
app.component('v-chart', Echarts)
app.config.globalProperties.$echarts = echarts

// ② 拿到pinia实例
const pinia = createPinia()

// 1 引入数据持久化插件
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
// 2 pinia使用数据持久化插件
pinia.use(piniaPluginPersistedstate)

app.use(ElementPlus)
app.use(pinia)
app.use(router)
app.use(vueI18n)

app.mount('#app')
